package com.chen.demo.simple.handler;

import com.chen.demo.simple.command.query.BookQuery;
import com.chen.demo.simple.domain.entity.Book;
import com.chen.demo.simple.repository.BookRepository;
import com.chen.winnerframework.cqrs.executor.CommandExecutor;
import com.chen.winnerframework.http.response.MultiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class BookQryExe implements CommandExecutor<BookQuery, MultiResponse<Book>> {

    private final BookRepository bookRepository;

    @Override
    public MultiResponse<Book> execute(BookQuery query) {
        List<Book> bookList = bookRepository.selectBookByName(query);
        return MultiResponse.success(bookList);
    }
}
